// pages/index/index.js
import request from "../../utils/request";


Page({

    /**
     * 页面的初始数据
     */
    data: {
        userInfo: {},
        bannerList: [],
        recommendList: [],
        topInList: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: async function (options) {
        let bannerListData = await request('/banner', {type: 2});
        this.setData({
            bannerList: bannerListData.banners,
        })

        let recommendListData = await request('/personalized');
        this.setData({
            recommendList: recommendListData.result,
        })


        let index=6450;
        let topResult=[];
        while (index<6455){
            let topListInData = await request('/artist/top/song',{id:index});
            let title
            switch (index) {
                case 6450:
                    title='杨溢升热歌榜';
                    break
                case 6451:
                    title='闫鑫泷热歌榜';
                    break
                case 6452:
                    title='周杰伦热歌榜';
                    break
                case 6453:
                    title='张震岳热歌榜';
                    break
                case 6454:
                    title='张信哲热歌榜';
                    break
            }
            let topListItem={name:title,tracks:topListInData.songs.slice(0,3)}
            topResult.push(topListItem)

            this.setData({
                topInList: topResult,
            })
            index ++
        }

    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    /**
     * 用户点击右上角分享
     */
    onShareAppMessage: function () {

    }
})